package com.cbn.ibcp.web.jishiting.statistic.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.cbn.ibcp.common.core.controller.BaseController;
import com.cbn.ibcp.jishiting.statistic.domain.OssInjectDataStatistic;
import com.cbn.ibcp.jishiting.statistic.service.IOssInjectDataStatisticService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/ossInjectDataStatistic")
@RequiredArgsConstructor
public class OssInjectDataStatisticController extends BaseController {

    private final IOssInjectDataStatisticService ossInjectDataStatisticService;


    @GetMapping("/getCurrentOssInjectDataStatistic")
    public OssInjectDataStatistic getCurrentOssInjectDataStatistic() {
        Date date = new Date();
        Date startTime = DateUtil.beginOfDay(date);
        Date endTime = DateUtil.endOfDay(date);
        return ossInjectDataStatisticService.getOssInjectDataStatistic(startTime, endTime);
    }

    @GetMapping("/getOssInjectDataStatisticList")
    public List<OssInjectDataStatistic> getOssInjectDataStatisticList(String dateStr) {
        Date date = new Date();
        if (StrUtil.isNotBlank(dateStr)) {
            date = DateUtil.parseDate(dateStr);
        }
        Date startTime = DateUtil.beginOfDay(date);
        Date endTime = DateUtil.endOfDay(date);
        return ossInjectDataStatisticService.selectList(startTime, endTime);
    }
}
